package ThreadWorker;

import java.util.HashMap;
import java.util.concurrent.Callable;

/**
* @author 李涛
* @version 创建时间：2018年8月26日 下午6:29:48
* 类说明
*/
public class Worker implements Callable<HashMap<String, Object>> {

	private String key;
	private IWorkContents work;

	public Worker(String key, IWorkContents doWork) {
		if (key == null || doWork == null) {
			throw new NullPointerException();
		}
		this.setKey(key);
		this.work = doWork;
	}

	@Override
	public HashMap<String, Object> call() throws Exception {
		// 执行业务代码
		Object rs = work.doWork();
		HashMap<String, Object> map = new HashMap<>();
		map.put(this.key, rs);
		return map;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

}
